package com.piece.core.framework.util.basic;

import com.piece.core.framework.constant.ExceptionConstants;
import com.piece.core.framework.constant.PermissionConstants;
import org.apache.commons.lang3.StringUtils;

/**
 * 权限信息工具
 */
public class PermissionUtil {
    /**
     * 权限错误消息提醒
     */
    public static String getMsg(String permission) {
        String msg = permission;
        if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.ADD_PERMISSION)) {
            msg = I18nUtil.message(ExceptionConstants.PERMISSION_CREATE);
        } else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EDIT_PERMISSION)) {
            msg = I18nUtil.message(ExceptionConstants.PERMISSION_EDIT);
        } else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.DELETE_PERMISSION)) {
            msg = I18nUtil.message(ExceptionConstants.PERMISSION_DELETE);
        } else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EXPORT_PERMISSION)) {
            msg = I18nUtil.message(ExceptionConstants.PERMISSION_EXPORT);
        } else if (StringUtils.endsWithAny(permission,
                new String[]{PermissionConstants.VIEW_PERMISSION, PermissionConstants.QUERY_PERMISSION})) {
            msg = I18nUtil.message(ExceptionConstants.PERMISSION_VIEW);
        }
        return msg;
    }
}
